package com.knife.blog.web.action;

import java.util.ArrayList;
import java.util.Collection;

//import com.knife.blog.domain.BlogCircle;
import com.knife.blog.domain.BlogCircleMember;
import com.knife.blog.domain.BlogInfo;
import com.knife.blog.domain.BlogMessage;
import com.knife.blog.domain.BlogNewsDoc;
import com.knife.blog.logic.BlogCircleDocService;
import com.knife.blog.logic.BlogCircleMemberService;
import com.knife.blog.logic.BlogCircleService;
import com.knife.blog.logic.CurrentUser;
import com.knife.blog.logic.impl.BlogCircleDocServiceImpl;
import com.knife.blog.logic.impl.BlogCircleMemberServiceImpl;
import com.knife.blog.logic.impl.BlogCircleServiceImpl;
import com.knife.blog.logic.impl.BlogCoreServiceImpl;
import com.knife.blog.logic.impl.BlogMessageServiceImpl;
import com.knife.blog.logic.impl.BlogReviewServiceImpl;
import com.knife.blog.logic.impl.PhotoServiceImpl;
import com.knife.util.CommUtil;
import com.knife.web.Module;
import com.knife.web.Page;
import com.knife.web.WebForm;
import com.knife.web.tools.IPageList;

public class BlogCircleManageAction extends BaseCrudAction {
	private BlogInfo circle;
	private static BlogCircleService circleService = BlogCircleServiceImpl.getInstance();
	private static BlogCircleMemberService circleMemberService = BlogCircleMemberServiceImpl.getInstance();
	private static BlogCircleDocService circleDocService = BlogCircleDocServiceImpl.getInstance();
	
	public Object doBefore(WebForm form, Module module) {
		circle = circleService.getBlogCircle((String)form.get("cid"));
		return super.doBefore(form, module);
	}

	@Override
	public IPageList doQuery(WebForm form, int currentPage, int pages) {
		//String command = (String)form.get("command");
		/*String scope = "circleCid=?";
		Collection paras = new ArrayList();
		paras.add((String)form.get("cid"));*/
		/*if(command.equals("showMember"))
		{
			form.addResult("list", circleMemberService.queryCircleMember(scope,paras,currentPage, pages).getResult());
		}else if(command.equals("showDoc")){
			form.addResult("list", circleDocService.queryDoc(scope , paras , currentPage, pages).getResult());
		}*/
		return null;
	}
	
	public void doAfter(WebForm form, Module module) {
		form.addResult("dirService", BlogCoreServiceImpl.getInstance());
		form.addResult("cocService", BlogCoreServiceImpl.getInstance());
		form.addResult("photService", PhotoServiceImpl.getInstance());
		form.addResult("reviewService", BlogReviewServiceImpl.getInstance());
		form.addResult("messageService", BlogMessageServiceImpl.getInstance());
		form.addResult("circleService", BlogCircleServiceImpl.getInstance());
		if (circle != null) {
			form.addResult("blog", circle);
			form.addResult("templateName", circle.getTemplate());
		}
		super.doAfter(form, module);
	}
	
	public Page doDelMember(WebForm form, Module module){
		boolean ret = circleMemberService.delCircleMember((String)form.get("cid"));
		form.addResult("msg", ret ? "删除成功!" : "删除失败!");
		return super.doQuery(form, module, this.getCurrentUser(form));
	}
	
	public Page doNominate(WebForm form, Module module){
		//BlogCircleDoc circleDoc = 
		return null;
		
	}

	@Override
	public Object form2Obj(WebForm form) {
		String cid = CommUtil.null2String(form.get("cid"));
		BlogNewsDoc circleDoc = circleDocService.getCircleDoc(cid);
		if (circleDoc == null)
			circleDoc = new BlogNewsDoc();
		form.toPo(circleDoc);
		return circleDoc;
	}
}
